package test;

import anaydis.sort.Sorter;
import anaydis.sort.gui.ObservableSorter;
import benchMark.BenchMarkImpl;
import data.IntegerDataSetGenerator;
import provider.SorterProviderImpl;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Keevu
 * Date: 04/10/11
 * Time: 19:03
 * To change this template use File | Settings | File Templates.
 */
public class QuickSortersTester {

 public static void main(String[] args) throws Exception {
        IntegerDataSetGenerator dataGenerator = new IntegerDataSetGenerator();
        SorterProviderImpl sorterProvider = new SorterProviderImpl();
        Iterable<Sorter> sorters = sorterProvider.getAllSorters();
        algorithmTest(dataGenerator, sorters);
    }

    private static void algorithmTest(IntegerDataSetGenerator dataGenerator, Iterable<Sorter> sorters) throws Exception {
        System.out.println("Resultado de las pruebas:");
        System.out.println("");
        randomTesting(dataGenerator, sorters);
    }

    private static void randomTesting(IntegerDataSetGenerator dataGenerator, Iterable<Sorter> sorters) throws Exception {
        for (int n = 10; n < 2000; n = n * 5) {
           System.out.println("Lista Random de "+n+" elementos:");
            List<Integer> list = dataGenerator.createRandom(n);
            for (Sorter sorter : sorters) {
                List<Integer> list2 = list;

               BenchMarkImpl benchMark = new BenchMarkImpl();
               ((ObservableSorter) sorter).addSorterListener(benchMark);
               long firstTime = System.currentTimeMillis();
               sorter.sort(dataGenerator.getComparator(), list2);
               long lastTime = System.currentTimeMillis();
             System.out.println("Con el metodo "+ sorter.getType().toString()+ " Se registraron los datos: Tiempo: " + (lastTime - firstTime) + " MiliSeg, " +
                        +benchMark.getSwaps() + " Swaps ," + benchMark.getComparisons() + " Comparaciones");
            }
            System.out.println("");
       }
    }

}
